<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>编辑旅客信息 - 航空订票系统</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/css/bootstrap.min.css">
</head>
<body>
    <nav class="navbar navbar-expand-lg navbar-dark bg-primary">
        <div class="container">
            <a class="navbar-brand" href="/flightbooking/">航空订票系统</a>
            <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav">
                <span class="navbar-toggler-icon"></span>
            </button>
            <div class="collapse navbar-collapse" id="navbarNav">
                <ul class="navbar-nav mr-auto">
                    <li class="nav-item">
                        <a class="nav-link" href="/flightbooking/">首页</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="/flightbooking/flights">航班管理</a>
                    </li>
                    <li class="nav-item active">
                        <a class="nav-link" href="/flightbooking/passengers">旅客管理</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="/flightbooking/tickets">票务管理</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="/flightbooking/dashboard">统计面板</a>
                    </li>
                </ul>
            </div>
        </div>
    </nav>

    <div class="container mt-4">
        <nav aria-label="breadcrumb">
            <ol class="breadcrumb">
                <li class="breadcrumb-item"><a href="/flightbooking/">首页</a></li>
                <li class="breadcrumb-item"><a href="/flightbooking/passengers">旅客管理</a></li>
                <li class="breadcrumb-item active" aria-current="page">编辑旅客信息</li>
            </ol>
        </nav>

        <div class="card">
            <div class="card-header bg-primary text-white">
                <h5 class="mb-0">编辑旅客信息</h5>
            </div>
            <div class="card-body">
                <form action="/flightbooking/passengers/edit" method="post" th:if="${passenger != null}">
                    <input type="hidden" name="passengerId" th:value="${passenger.passengerId}">
                    <div class="row">
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="passengerId">旅客ID</label>
                                <input type="text" class="form-control" id="passengerId" th:value="${passenger.passengerId}" disabled>
                            </div>
                            <div class="form-group">
                                <label for="name">姓名 <span class="text-danger">*</span></label>
                                <input type="text" class="form-control" id="name" name="name" th:value="${passenger.name}" required>
                            </div>
                            <div class="form-group">
                                <label for="idCard">身份证号 <span class="text-danger">*</span></label>
                                <input type="text" class="form-control" id="idCard" name="idCard" 
                                       pattern="[0-9Xx]{18}" title="请输入18位有效身份证号" 
                                       th:value="${passenger.idCard}" required>
                                <small class="form-text text-muted">请输入18位有效身份证号</small>
                            </div>
                            <div class="form-group">
                                <label for="phone">联系电话 <span class="text-danger">*</span></label>
                                <input type="tel" class="form-control" id="phone" name="phone" 
                                       pattern="[0-9]{11}" title="请输入11位手机号码" 
                                       th:value="${passenger.phone}" required>
                                <small class="form-text text-muted">请输入11位手机号码</small>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="email">电子邮箱</label>
                                <input type="email" class="form-control" id="email" name="email" th:value="${passenger.email}">
                            </div>
                            <div class="form-group">
                                <label for="totalPurchase">历史购票金额</label>
                                <div class="input-group">
                                    <div class="input-group-prepend">
                                        <span class="input-group-text">¥</span>
                                    </div>
                                    <input type="number" class="form-control" id="totalPurchase" name="totalPurchase" 
                                           min="0" step="0.01" th:value="${passenger.totalPurchase}">
                                </div>
                                <small class="form-text text-muted">修改此值可能会影响旅客的VIP折扣率</small>
                            </div>
                            <div class="form-group">
                                <label for="vipDiscount">VIP折扣率</label>
                                <div class="input-group">
                                    <input type="number" class="form-control" id="vipDiscount" name="vipDiscount" 
                                           min="0.1" max="1" step="0.01" th:value="${passenger.vipDiscount}">
                                    <div class="input-group-append">
                                        <span class="input-group-text">折</span>
                                    </div>
                                </div>
                                <small class="form-text text-muted">值越小折扣越大，1.00表示无折扣</small>
                            </div>
                            <div class="form-group">
                                <label>注册时间</label>
                                <input type="text" class="form-control" th:value="${#dates.format(passenger.registrationDate, 'yyyy-MM-dd HH:mm')}" disabled>
                            </div>
                        </div>
                    </div>
                    <div class="text-right">
                        <a href="/flightbooking/passengers" class="btn btn-secondary">取消</a>
                        <button type="submit" class="btn btn-primary">保存</button>
                    </div>
                </form>
                
                <div class="alert alert-danger" th:if="${passenger == null}">
                    未找到旅客信息，无法编辑。<a href="/flightbooking/passengers" class="alert-link">返回旅客列表</a>
                </div>
            </div>
        </div>
    </div>
    
    <footer class="bg-dark text-light mt-5 py-3">
        <div class="container text-center">
            <p class="mb-0">© 2023 航空订票系统 - JZA04</p>
        </div>
    </footer>

    <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/js/bootstrap.bundle.min.js"></script>
    <script>
        // 当历史购票金额变更时，自动调整VIP折扣率
        document.getElementById('totalPurchase').addEventListener('input', function() {
            const totalPurchase = parseFloat(this.value) || 0;
            const vipDiscountEl = document.getElementById('vipDiscount');
            
            if (totalPurchase >= 10000) {
                vipDiscountEl.value = 0.80;
            } else if (totalPurchase >= 5000) {
                vipDiscountEl.value = 0.85;
            } else if (totalPurchase >= 3000) {
                vipDiscountEl.value = 0.90;
            } else if (totalPurchase >= 1000) {
                vipDiscountEl.value = 0.95;
            } else {
                vipDiscountEl.value = 1.00;
            }
        });
    </script>
</body>
</html> 